// type==1专栏
// type==2资讯
// type==4视频
// type==3问答
<template>
    <div class="operate">
        <div class="operate_cell">
            <div class="weui-cell__bd" v-if="iszan">
                 <van-button class="appppp" type="" open-type="getUserInfo" @getuserinfo="bindGetUserInfo($event,info,1)" @click.stop>
                    <img src="/static/images/message_01.png" v-if="info.is_zan==0"/> 
                    <img src="/static/images/ic_love@2x.png" v-else/> {{info.zans}}{{info.zan}}
                </van-button>
            </div> 
            <div class="weui-cell__bd" v-if="iszanCon">
                 <van-button class="appppp" type="" open-type="getUserInfo" @getuserinfo="bindGetUserInfo($event,info,2)" @click.stop>
                    <img src="/static/images/message_01.png" v-if="info.is_zan==0"/> 
                    <img src="/static/images/ic_love@2x.png" v-else/> {{info.zan}}
                </van-button>
            </div> 
            <div class="weui-cell__bd" v-if="islook">
                 <van-button class="appppp" type="" open-type="getUserInfo">
                    <img src="/static/images/ic_look@2x.png" style="width:17px;height:10px"/> {{info.views}}
                </van-button>
            </div>
            <div class="weui-cell__bd" v-if="iscomt">
                <van-button class="appppp" type="" open-type="getUserInfo" @click.stop="tocomment(info)">
                    <img src="/static/images/message_02.png"/> {{info.comments}}
                </van-button>
            </div>
            <div class="weui-cell__bd" v-if="iscomts">
                <van-button class="appppp" type="" open-type="getUserInfo">
                    <img src="/static/images/message_02.png"/> {{info.comment}}{{info.comments}}
                </van-button>
            </div>
            <div class="weui-cell__bd" v-if="isques">
                <van-button class="appppp" type="" open-type="getUserInfo" @click.stop="toreply(info)">
                    <img src="/static/images/message_02.png"/> {{info.comment}}
                </van-button>
            </div>
            <div class="weui-cell__bd" v-if="isshare">
                 <van-button class="appppp" type="" open-type="share" @click.stop>
                    <img src="/static/images/message_03.png" class="grayShare"/> 
                    <span v-if="isnum"> {{info.forwards}}</span>
                    <span v-else> 转发</span>
                 </van-button>
            </div>
        </div>
    </div>
</template>

<script>
import {like} from "@/api/operate.js"
import {zanComment} from "@/api/operate.js"
import { xdLogin } from "@/utils/login"
export default {
    props: ["info","type","iszan","iscomt","isshare","isques","islook","isnum","iscomts","iszanCon"],
    methods:{
        tocomment(info){
            var url;
            switch (info.article_type) {
                case 1: 
                     url="../speacilDetail/main?isz=1&id="+info.id+"&keType="+info.article_type;
                     mpvue.navigateTo({url})
                break;

                case 2:
                    url="../speacilDetail/main?isz=0&id="+info.id+"&keType="+info.article_type;
                    mpvue.navigateTo({url})     
                break;

                case 3: 
                    url="../questionDetail/main?&id="+info.id+"&keType="+info.article_type;
                    mpvue.navigateTo({url})  
                break;

                case 4:
                    url="../videoDetail/main?&id="+info.id+"&keType="+info.article_type;
                    mpvue.navigateTo({url})  
                break;

                case 5:
                break;

                case 6:
                break;  

                default:
                    break;
            }
        },
        toreply(info){
            let comment=JSON.stringify(info)
            let url="../writeComment/main?info="+comment+"&type=2&actType=3"
            mpvue.navigateTo({url})
        },
        tolike(info){
            let data={};
            data.id=info.id
            data.type=info.article_type;
            like(data).then(res=>{
                let msg=res.msg
                wx.showToast({
                    title: msg,
                    icon: 'none',
                    success: (result) => {
                        if(info.is_zan==0){ 
                            info.zans=parseInt(info.zans)+1  
                            info.is_zan=1
                        }else{
                            info.zans=parseInt(info.zans)-1 
                            info.is_zan=0
                        }

                        // this.$emit("like",{info})
                    },
                    fail: () => {},
                    complete: () => {}
                });
            }) 
        },
        toLikeCon(info){
            let data={};
            data.id=info.id
            data.type=3;
            zanComment(data).then(res=>{
                let msg=res.msg
                wx.showToast({
                    title: msg,
                    icon: 'none',
                    success: (result) => {
                        if(info.is_zan==0){ 
                            info.zan=parseInt(info.zan)+1  
                            info.is_zan=1
                        }else{
                            info.zan=parseInt(info.zan)-1 
                            info.is_zan=0
                        }

                        // this.$emit("like",{info})
                    },
                    fail: () => {},
                    complete: () => {}
                });
            }) 
        },
        bindGetUserInfo(e,info,type){
            wx.getStorage({
                key: 'token',
                success: (result) => {
                    if(type==1)  {
                       this.tolike(info)
                    } else if(type==2) {
                       this.toLikeCon(info)
                    }
                },
                fail: () => {
                    xdLogin(e).then((res)=>{
                        if(type==1)  {
                           this.tolike(info)
                        } else if(type==2) {
                           this.toLikeCon(info)
                        }
                    })
                },
                complete: () => {}
            });
              
            console.log(e,info)
            
          
        }
    }
}
</script>

<style lang="scss" >
.operate_cell{
    display: flex;
}
.appppp{
    .van-button{
        background:transparent !important;
        height:auto !important;
        line-height:1.5 !important;
        padding:0 !important;
        padding:0 5px;
        width: 100%;
    }
    .button-hover {
        background-color:transparent !important;
    }
    .van-button--active{
        background-color:transparent !important;
    }
    button{
        width: 100%;
    }
}

.van-col{
    color:#333;
}

.operate{
    font-size:14px;
    font-weight:500;
    line-height:1;
    text-align:center;
    width:100%;
   
    img{
        width:16px;
        height:14px;
        display:inline-block;
        vertical-align:middle;
    }
    .grayShare{
        width:14px;
        height:14px;
    }
}
</style>
